package com.example.swim.Service;


import com.example.swim.Dao.VipDao;
import com.example.swim.Pojo.VIP;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Random;

/**
 * @author LiYa
 * @create 2022-07-18 17:46
 */
@Transactional
@Service
public class VipService  {
    @Autowired
    VipDao vipDao;
    public List<VIP> findAll()
    {
      return   vipDao.findAll();
    }
    public long insertVIP(VIP vip)
    {
        vipDao.insertVIP(vip);
        return vip.getId();
    }
    public void del(Integer id)
    {
        vipDao.delVIP(id);
        System.out.println("删除vip用户成功");
    }
    public void update(VIP vip)
    {
        vipDao.updateVIP(vip);
        System.out.println("修改vip用户成功");
    }
    public VIP findVIP(VIP vip)
    {
        return vipDao.findVIP(vip);
    }
    public VIP findVIP(int id)
    {
        return vipDao.selectById(id);
    }

    public void addAid(Integer aid,Integer id)
    {
        vipDao.addAid(aid,id);
        System.out.println("会员报名活动成功");
    }
    public VIP quitA(VIP vip){
        vip.setAid(null);
        vipDao.updateVIP(vip);
        return vip;
    }

    public void buyCard(int id,int cid){
        VIP vip=new VIP();
        vip.setId(id);
        vip.setGrade(cid);
        vipDao.updateById(vip);
    }
}
